package edu.sju.ssm;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;


import edu.sju.ssm.service.PrintingService;
import edu.sju.ssm.serviceImpl.ConsolePrintingService;
import edu.sju.ssm.serviceImpl.FilePrintingService;

@Configuration
@PropertySource("classpath:printing-config.txt")
public class PrintingApp {
	
	@Value("${message}")
    private String message;
    @Value("${filePath}")
    private String filePath;

	@Bean
	public ConsolePrintingService printService() {
		return new ConsolePrintingService(message);
	}
	
	@Bean
	public FilePrintingService filePrintingService() {
		return new FilePrintingService(filePath,message);
	}
	
	
	public static void main(String[] args) {

		AnnotationConfigApplicationContext appContext=
		new AnnotationConfigApplicationContext(PrintingApp.class);
//		ApplicationContext appContext=
//				new ClassPathXmlApplicationContext("applicationContext.xml");
//		
		PrintingService ps= appContext.getBean("printService",PrintingService.class);
		ps.print();
		PrintingService ps1=appContext.getBean("filePrintingService",PrintingService.class);
		ps1.print();
		
		
		((AbstractApplicationContext) appContext).close();

	}
}
